package com.example.demo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.context.request.async.DeferredResult;

@SpringBootApplication
@EnableBinding(myChannel.class)
@EnableAsync
public class RmqtestandnettyApplication {
	@Autowired
	myChannel channel;
	
	public static void main(String[] args) {
		SpringApplication.run(RmqtestandnettyApplication.class, args);
	}
	
	@StreamListener(myChannel.CONSUMER)//接收消息监听
//	@SendTo(myChannel.PRODUCTOR)
	public void reciver(String msg) {
    	synchronized(APIController.holder) {
    		DeferredResult<String> df=APIController.holder.get("1");
    		df.setResult(msg);//唤醒异步请求线程
    	}
//        if (msg.equals("HELLO")) {
//            // giving up - don't send to DLX
//            throw new ImmediateAcknowledgeAmqpException("垃圾数据直接丢掉");//不放入死信队列
//        }
//        throw new AmqpRejectAndDontRequeueException("我处理不了，叫别人试试----放到死信队列");
	}
}
